package model

import (
	"github.com/jjl309/oneGroup"
	"gorm.io/gorm"
)

type FreshFood struct {
	gorm.Model
	Name      string  `gorm:"column:name;type:varchar(30);not null" json:"name"`
	Price     float64 `gorm:"column:price;type:decimal(10,2);not null" json:"price"`
	Image     string  `gorm:"column:image;type:varchar(255);not null" json:"image"`
	Stock     int     `gorm:"column:stock;type:int(11);not null" json:"stock"`
	Attribute int     `gorm:"column:attribute;type:int(11);not null" json:"attribute"`
}

func (f *FreshFood) TableName() string {
	return "fresh_food"
}
func (f *FreshFood) GetFreshFoodInfoById(id int) error {
	return oneGroup.DB.Model(&FreshFood{}).Where("id = ?", id).Limit(1).Find(f).Error
}
func (f *FreshFood) UpdateStockById(stock int) error {
	return oneGroup.DB.Model(&FreshFood{}).Where("id = ?", f.ID).Update("stock", f.Stock-stock).Error
}
